package com.nsn.auction.domina;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Represents each single User
 */
@Entity
@Table(name="USER")
public class User implements Serializable{
	
	private Long userId;
	private String firstName;
	private String lastName;
	private String email;
	private String password;
	
	public User() {}
	
	public User(String firstName, String lastName, String email) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}
	public User(String firstName, String lastName, String email, String password) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.password = password;
	}
	
	@Column(name="FIRST_NAME", nullable = false, length = 20)
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	@Column(name="LAST_NAME", nullable = false, length = 20)
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	@Column(name="EMAIL", nullable = false, length = 30)
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="USER_ID", unique = true, nullable = false)
	public Long getUserId() {
		return userId;
	}
	
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	@Column(name="PASSWORD", nullable = false, length = 30)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@Override
	public boolean equals(Object object) {
		
		//check for selt-comparison
		if (this == object) return true;
		if (!( this.getClass().equals(object.getClass()) )) return false;
		
		User temp_user = (User) object;
		 return (null == getFirstName() ? null == temp_user.getFirstName() : getFirstName().equals(temp_user.getFirstName()) && 
				null == getLastName() ? null == temp_user.getLastName() : getLastName().equals(temp_user.getLastName()) &&
				null == getEmail() ? null == temp_user.getEmail() : getEmail().equals(temp_user.getEmail()) &&	
				null == getPassword() ? null == temp_user.getPassword() : getPassword().equals(temp_user.getPassword()));
	}
	
	
}
